package tms.model;

import java.util.Calendar;
import java.util.Date;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import tms.service.ServiceHandler;

@XmlRootElement
public class Booking{

    public static String tableName = "Booking";

    public static String[] columns = {"TicketNumber", "IDFlight", "IDBookingAccount",
            "PassengerName", "PassengerPassport", "PassengerPID", "TicketClass",
            "TotalAmount", "IsActive", "SeatNumber", "PassengerPhone", "PassengerEmail",
            "BookingPersonPhone", "BookingPersonEmail", "BookingPersonName",
            "BookingDay", "BookingMonth", "BookingYear", "BookingHour", "BookingMinute"};

    private int id = -1;
    private String ticketNumber = "";
    private int idFlight = -1;
    private int idBookingAccount = -1;
    private String passengerName = "";
    private String passengerPassport = "";
    private String passengerPID = "";
    private String ticketClass = "";
    private double totalAmount = 0;
    private boolean isActive = false;
    private int seatNumber = 0;
    private String passengerPhone = "";
    private String passengerEmail = "";
    private String bookingPersonPhone = "";
    private String bookingPersonEmail = "";
    private String bookingPersonName = "";

    private int bDay = 1;
    private int bMonth = 1;
    private int bYear = 2013;
    private int bHour = 0;
    private int bMin = 0;

    private Flight flight = null;
    private Account bookingAccount = null;

    /**
     * Load Flight information by IDFlight.
     */
    private void bindingFlight(int idFlight) {
        if (idFlight > 0) {
            setFlight(ServiceHandler.getFirstFlight("Flight.ID = " + idFlight));
        }
    }

    /**
     * Load BookingAccount by IDBookingAccount.
     */
    private void bindingBookingAccount(int idBookingAccount) {
        if (idBookingAccount > 0) {
            setBookingAccount(ServiceHandler.getFirstAccount("Account.ID = " + idBookingAccount));
        }
   }

    public String[] getValues() {
        return new String[] {"'" + getTicketNumber() + "'", getIdFlight() + "", getIdBookingAccount() + "",
                "'" + getPassengerName() + "'", "'" + getPassengerPassport() + "'",
                "'" + getPassengerPID() + "'", "'" + getTicketClass() + "'", getTotalAmount() + "",
                isActive() == true ? "1" : "0", getSeatNumber() + "", "'" + getPassengerPhone() + "'",
                "'" + getPassengerEmail() + "'", "'" + getBookingPersonPhone() + "'", "'" + getBookingPersonEmail() + "'",
                "'" + getBookingPersonName() + "'", getbDay() + "", getbMonth() + "", getbYear() + "", getbHour() + "", getbMin() + ""};
   }

    /****************************************************************************/

    @XmlElement
    public String getTicketNumber() {
        return ticketNumber;
   }

    public void setTicketNumber(String ticketNumber) {
        this.ticketNumber = ticketNumber;
   }

    @XmlElement
    public int getIdFlight() {
        return idFlight;
   }

    public void setIdFlight(int idFlight) {
        this.idFlight = idFlight;
        bindingFlight(idFlight);
   }

    @XmlElement
    public int getIdBookingAccount() {
        return idBookingAccount;
   }

    public void setIdBookingAccount(int idBookingAccount) {
        this.idBookingAccount = idBookingAccount;
        bindingBookingAccount(idBookingAccount);
   }

    @XmlElement
    public String getPassengerName() {
        return passengerName;
   }

    public void setPassengerName(String passengerName) {
        this.passengerName = passengerName;
   }

    @XmlElement
    public String getPassengerPassport() {
        return passengerPassport;
   }

    public void setPassengerPassport(String passengerPassport) {
        this.passengerPassport = passengerPassport;
   }

    @XmlElement
    public String getPassengerPID() {
        return passengerPID;
   }

    public void setPassengerPID(String passengerPID) {
        this.passengerPID = passengerPID;
   }

    @XmlElement
    public String getTicketClass() {
        return ticketClass;
   }

    public void setTicketClass(String ticketClass) {
        this.ticketClass = ticketClass;
   }

    @XmlElement
    public double getTotalAmount() {
        return totalAmount;
   }


    public void setTotalAmount(double totalAmount) {
        this.totalAmount = totalAmount;
   }

    @XmlElement
    public boolean isActive() {
        return isActive;
   }

    public void setActive(boolean isActive) {
        this.isActive = isActive;
   }

    @XmlElement
    public int getId() {
        return id;
   }

    public void setId(int id){
    	this.id = id;
    }
    
    public Flight getFlight() {
        return flight;
   }

    public void setFlight(Flight flight) {
        this.flight = flight;
        this.idFlight = flight.getId();
   }

    public Account getBookingAccount() {
        return bookingAccount;
   }

    public void setBookingAccount(Account bookingAccount) {
        this.bookingAccount = bookingAccount;
   }

    @XmlElement
    public int getSeatNumber() {
        return seatNumber;
   }

    public void setSeatNumber(int seatNumber) {
        this.seatNumber = seatNumber;
   }

    @XmlElement
    public String getPassengerPhone() {
        return passengerPhone;
   }

    public void setPassengerPhone(String passengerPhone) {
        this.passengerPhone = passengerPhone;
   }

    @XmlElement
    public String getPassengerEmail() {
        return passengerEmail;
   }

    public void setPassengerEmail(String passengerEmail) {
        this.passengerEmail = passengerEmail;
   }

    @XmlElement
    public String getBookingPersonPhone() {
        return bookingPersonPhone;
   }

    public void setBookingPersonPhone(String bookingPersonPhone) {
        this.bookingPersonPhone = bookingPersonPhone;
   }

    @XmlElement
    public String getBookingPersonEmail() {
        return bookingPersonEmail;
   }

    public void setBookingPersonEmail(String bookingPersonEmail) {
        this.bookingPersonEmail = bookingPersonEmail;
   }

    @XmlElement
    public String getBookingPersonName() {
        return bookingPersonName;
   }

    public void setBookingPersonName(String bookingPersonName) {
        this.bookingPersonName = bookingPersonName;
   }

    public Date getBookingDate() {
        Calendar c = Calendar.getInstance();
        c.set(getbYear(), getbMonth() - 1, getbDay(), getbHour(), getbMin());
        return c.getTime();
   }

    public void setBookingDate(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        setbDay(c.get(Calendar.DAY_OF_MONTH));
        setbMonth(c.get(Calendar.MONTH) + 1);
        setbYear(c.get(Calendar.YEAR));
        setbHour(c.get(Calendar.HOUR_OF_DAY));
        setbMin(c.get(Calendar.MINUTE));
   }

    @XmlElement
    public int getbDay() {
        return bDay;
    }

    private void setbDay(int bDay) {
        this.bDay = bDay;
    }

    @XmlElement
    public int getbMonth() {
        return bMonth;
    }

    public void setbMonth(int bMonth) {
        this.bMonth = bMonth;
    }

    @XmlElement
    private int getbYear() {
        return bYear;
    }

    private void setbYear(int bYear) {
        this.bYear = bYear;
    }

    @XmlElement
    private int getbHour() {
        return bHour;
    }

    private void setbHour(int bHour) {
        this.bHour = bHour;
    }

    @XmlElement
    private int getbMin() {
        return bMin;
    }

    private void setbMin(int bMin) {
        this.bMin = bMin;
    }
}
